package Interfaz;
import Logica.Manejadora;
import java.awt.*;
import java.util.*;
import javax.swing.*;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;


 /*
 * Interfaz.java
 *
 * Created on 23-sep-2011, 7:48:46
 */
/**
 *
 * @author Andrea Santos Morales
 */

public class Interfaz extends JFrame implements ActionListener{
    private Manejadora m;
    private ArrayList a;
    private Plano plano;
    private JButton boton;
    private JLabel ingreso;
    private JLabel valx;
    private JLabel valy;
    private JTextField xingresado;
    private JTextField yingresado;
    private JLabel analisis;
    private JLabel valmax;
    private JLabel valmax1;
    private JLabel prom;
    private JLabel prom1;
    private JLabel suma;
    private JLabel suma1;
    private JPanel grafica;
    private JPanel datos;
    private JPanel coordenadas;
    private JPanel estadistica;
    private JPanel ana;
    private JPanel total;
    private JLabel titulo;

    public Interfaz() {
        m= new Manejadora();
        m.empezar();
        a=m.getDatos();
        plano=new Plano(a);
        comenzar();
        boton.setActionCommand("boton");
        boton.addActionListener(this);
    }
       
     public static void main(String [] arg) throws Exception{
          Interfaz in= new Interfaz();
          in.setVisible(true);
     }
     
      public void comenzar(){
         setSize(800,500);
         setLayout(new BorderLayout());
         boton= new JButton("Enviar");
         titulo= new JLabel("Graficadora de Datos");
         ingreso= new JLabel("Ingreso de Nuevos Datos");
         valx= new JLabel("Coordenada X");
         valy= new JLabel("Coordenada Y");
         xingresado= new JTextField();
         yingresado= new JTextField();
         analisis= new JLabel("Análisis Estadístico");
         valmax= new JLabel("Valor Máximo");
         valmax1=new JLabel();
         prom= new JLabel("Promedio");
         prom1= new JLabel();
         suma= new JLabel("Suma Total");
         suma1= new JLabel();
         grafica= new JPanel();
         datos= new JPanel();
         datos.setLayout(new GridLayout(5,1));
         coordenadas= new JPanel();
         coordenadas.setLayout(new GridLayout(3,2));
         estadistica= new JPanel();
         estadistica.setLayout(new GridLayout(4,1));
         ana= new JPanel();
         ana.setLayout(new GridLayout(1,3));
         total= new JPanel();
         total.setLayout(new GridLayout(3,4));
         
         valmax1.setText(""+m.valMax());
         prom1.setText(""+m.prom());
         suma1.setText(""+m.suma());
         
         valx.setFont(new Font("Tahoma",1,14));
         valy.setFont(new Font("Tahoma",1,14));
         valmax.setFont(new Font("Tahoma",1,14));
         prom.setFont(new Font("Tahoma",1,14));
         suma.setFont(new Font("Tahoma",1,14));
         
         titulo.setFont(new Font("Tahoma",1,16));
         titulo.setForeground(new Color(0,0,102));
         titulo.setHorizontalAlignment(JTextField.CENTER);
         ingreso.setFont(new Font("Tahoma",1,16));
         ingreso.setForeground(new Color(0,0,102));
         analisis.setFont(new Font("Tahoma",1,16));
         analisis.setForeground(new Color(0,0,102));
         
         coordenadas.add(valx);
         coordenadas.add(xingresado);
         coordenadas.add(valy);
         coordenadas.add(yingresado);
         coordenadas.add(new JLabel(""));
         coordenadas.add(boton);
         
         datos.add(new JLabel(""));
         datos.add(ingreso);
         datos.add(new JLabel(""));
         datos.add(coordenadas);
         datos.add(new JLabel(""));
         
         ana.add(new JLabel(""));
         ana.add(analisis);
         ana.add(new JLabel(""));
         
         total.add(new JLabel(""));
         total.add(suma);
         total.add(suma1);
         total.add(new JLabel(""));
         total.add(new JLabel(""));
         total.add(prom);
         total.add(prom1);
         total.add(new JLabel(""));
         total.add(new JLabel(""));
         total.add(valmax);
         total.add(valmax1);
         total.add(new JLabel(""));
         
         estadistica.add(new JLabel(""));
         estadistica.add(ana);
         estadistica.add(total);
         estadistica.add(new JLabel(""));
         
         grafica.add(plano);
         
         add(titulo, BorderLayout.NORTH);
         add(grafica, BorderLayout.CENTER);
         add(datos, BorderLayout.EAST); 
         add(estadistica, BorderLayout.SOUTH);
         setTitle("Graficadora de Datos");
         setLocationRelativeTo(null);
    }

    public void actionPerformed(ActionEvent evento){
        String s = evento.getActionCommand();
		
        if(s.equals("boton")==true){
             m.setdatox(Integer.parseInt(xingresado.getText()));
             m.setdatoy(Integer.parseInt(yingresado.getText()));
             m.IngresoDato();
             valmax1.setText("" + m.valMax());
             suma1.setText("" + m.suma());
             prom1.setText("" + m.prom());
             plano.repaint();
             this.update(this.getGraphics());
        }
    }
    
}